// Audio Player Script - Anantha Narayan SAN Gear  http://www.geocities.com/delabs/
//
//display pv digits
var seg_0 = new Image();
seg_0.src = "skins/sg0.png";
var seg_1 = new Image();
seg_1.src = "skins/sg1.png";
var seg_2 = new Image();
seg_2.src = "skins/sg2.png";
var seg_3 = new Image();
seg_3.src = "skins/sg3.png";
var seg_4 = new Image();
seg_4.src = "skins/sg4.png";
var seg_5 = new Image();
seg_5.src = "skins/sg5.png";
var seg_6 = new Image();
seg_6.src = "skins/sg6.png";
var seg_7 = new Image();
seg_7.src = "skins/sg7.png";
var seg_8 = new Image();
seg_8.src = "skins/sg8.png";
var seg_9 = new Image();
seg_9.src = "skins/sg9.png";
//
//skins images
var back_0 = new Image();
back_0.src = "skins/s0/back.png";
var frame_0 = new Image();
frame_0.src = "skins/s0/frame.png";
var back_1 = new Image();
back_1.src = "skins/s1/back.png";
var frame_1 = new Image();
frame_1.src = "skins/s1/frame.png";
var back_2 = new Image();
back_2.src = "skins/s2/back.png";
var frame_2 = new Image();
frame_2.src = "skins/s2/frame.png";
//
var play_0 = new Image();
play_0.src = "skins/s0/play.png";
var stop_0 = new Image();
stop_0.src = "skins/s0/stop.png";
var next_0 = new Image();
next_0.src = "skins/s0/next.png";
var prev_0 = new Image();
prev_0.src = "skins/s0/prev.png";
//
var play_1 = new Image();
play_1.src = "skins/s1/play.png";
var stop_1 = new Image();
stop_1.src = "skins/s1/stop.png";
var next_1 = new Image();
next_1.src = "skins/s1/next.png";
var prev_1 = new Image();
prev_1.src = "skins/s1/prev.png";
//
var play_2 = new Image();
play_2.src = "skins/s2/play.png";
var stop_2 = new Image();
stop_2.src = "skins/s2/stop.png";
var next_2 = new Image();
next_2.src = "skins/s2/next.png";
var prev_2 = new Image();
prev_2.src = "skins/s2/prev.png";
//
var play_led;
var stop_led;
var prev_led;
var next_led;
var skin_back;
var skin_frame;
var sel_skin=0;
//
var act_track=0;
var act_strn;
//
var cook_all="";
//
var ap_track = new Array();  // pipe seperated track data
var cook_file = new Array();  //each file holds 10 tracks and put into a cookie
//
cook_file[0]="";cook_file[1]="";cook_file[2]="";cook_file[3]="";cook_file[4]="";
cook_file[5]="";cook_file[6]="";cook_file[7]="";cook_file[8]="";cook_file[9]="";
//
function start_player(){
sound5Play(click_sound);
play_led = document.getElementById('play-btn');
stop_led = document.getElementById('stop-btn');
prev_led = document.getElementById('prev-btn');
next_led = document.getElementById('next-btn');
//
skin_back = document.getElementById('back-cloth');
skin_frame = document.getElementById('frame-holder');
load_mem();
}
//
function play_track() {
if (ap_songs[act_track]!=undefined && ap_songs[act_track]!=""){
sound5Play(ap_songs[act_track]);
play_led.style.background = "yellow";
linktext[1] = ap_title[act_track];
show_text(1,'status_box');
}
else{
show_text(0,'status_box');
sound5Stop();
}
show_number();
}
//
//
function stop_track() {
sound5Stop();
stop_led.style.background = "yellow";
play_led.style.background = "#E6E6FA";
linktext[1] = "Ok, I will keep Quiet";
show_text(1,'status_box');
window.setTimeout("stop_off();",2000);
}
//
function stop_off() {
sound5Play(click_sound);
stop_led.style.background = "#E6E6FA";
}
//
function prev_track() {
if (ap_songs[act_track-1]!=undefined && act_track>0){
act_track--;
play_track();
}
else
{
stop_track();
show_text(0,'status_box');
}
prev_led.style.background = "yellow";
window.setTimeout("prev_off();",4000);
}
//
function prev_off() {
prev_led.style.background = "#E6E6FA";
}
//
function next_track() {
if (ap_songs[act_track]!=undefined && act_track<99 && ap_songs[act_track]!=""){
act_track++;
play_track();
}
else{
stop_track();
show_text(0,'status_box');
}
next_led.style.background = "yellow";
window.setTimeout("next_off();",4000);
}
//
function next_off() {
next_led.style.background = "#E6E6FA";
}
//
//
function show_number() {
if(act_track>9){act_strn = "h"+ act_track;}
else{act_strn = "h0"+ act_track;}
//
document.images.sd_2.src = eval("seg_" + act_strn.charAt(2) + ".src");
document.images.sd_1.src = eval("seg_" + act_strn.charAt(1) + ".src");
}
//
function set_sd2() {
if (ap_songs[act_track]!=undefined && act_track<99 && ap_songs[act_track]!=""){
act_track = act_track +1;
}
else{act_track=0;}
show_number();
if (edit_live == 1){edit_it();}
}
//
function set_sd1() {
if (ap_songs[act_track+10]!=undefined && act_track<90 && ap_songs[act_track+10]!=""){
act_track = act_track +10;
}
else{act_track=0;}
show_number();
if (edit_live == 1){edit_it();}
}
//
var act_url="url";
var act_title="title";
var edit_live=0;
var restore_live=0;
//
function edit_it() {
act_url = ap_songs[act_track];
act_title = ap_title[act_track];
linktext[4]="<form name='take_song' action=''><input  maxlength='50' class='inp_type' name='take_title' size='34' value='" + act_title + "' type='text'><br><input  maxlength='100' class='inp_type' name='take_url' size='34' value='" + act_url + "' type='text'><br>Title above, URL Below, Save.</form>"
show_text(4,'status_box');
edit_live = 1;
restore_live =0;
}
//
function save_it() {
if (edit_live == 1){
ap_songs[act_track] = document.take_song.take_url.value;
ap_title[act_track] = document.take_song.take_title.value;
edit_live = 0;
linktext[2]="Track and Title Saved,<br>for Song Number <b>" + act_track + "</b>. "
show_text(2,'status_box');
}
if (restore_live == 1){
cook_all = document.back_form.back_text.value;
restore_live = 0;
show_text(3,'status_box');
set_tracks();
}
save_tracks();
}
//
var act_range=0;
var act_span=0;
//
function save_tracks() {
//
cook_all= "";
for (ar = 0; ar < 10; ar++){
act_range =ar;
act_span = act_range*10;
cook_file[act_range] ="";
//
for (i = act_span; i < (act_span+10); i++){
if (ap_songs[i] != undefined){
ap_track[i] = i + "|" + ap_title[i] + "|" +  ap_songs[i] + "||"
cook_file[act_range] = cook_file[act_range] + ap_track[i];
}
}
cook_all = cook_all + cook_file[i];
}
save_mem();
}
//
var track_temp=new Array();
//
function load_tracks() {
cook_all= "";
for (i = 0; i < 10; i++){cook_all = cook_all + cook_file[i];}
//
ap_track = cook_all.split("||");
//
for (i = 0; i < 100; i++){
if (ap_track[i] != undefined){
track_temp = ap_track[i].split("|");
ap_title[i]=track_temp[1];
ap_songs[i]=track_temp[2];
}
else
{
ap_title[i]="";
ap_songs[i]="";
}
}
}
//
//
function set_tracks() {
ap_track = cook_all.split("||");
//
for (i = 0; i < 100; i++){
if (ap_track[i] != undefined){
track_temp = ap_track[i].split("|");
ap_title[i]=track_temp[1];
ap_songs[i]=track_temp[2];
}
else
{
ap_title[i]="";
ap_songs[i]="";
}
}
}
//
function backup_psv() {
cook_all= "";
for (i = 0; i < 100; i++){
if (ap_songs[i] != undefined){
ap_track[i] = i + "|" + ap_title[i] + "|" +  ap_songs[i] + "||"
cook_all = cook_all + ap_track[i];
}
}
linktext[6]="<form name='back_form' action=''><textarea readonly='readonly' name='back_text' rows='3' cols='33'>"+ cook_all + "</textarea></form>";
show_text(6,'status_box');
copy(cook_all);
}
//
function restore_psv() {
linktext[6]="<form name='back_form' action=''><textarea name='back_text' rows='3' cols='33'>Clear this text, Paste your PSV data here and Press Save.</textarea></form>";
show_text(6,'status_box');
restore_live =1;
edit_live = 0;
}
//
function set_skin() {
linktext[5]="<img onclick='set_sx(0);' src='skins/s0.png' border=0><img onclick='set_sx(1);' src='skins/s1.png' border=0><img onclick='set_sx(2);' src='skins/s2.png' border=0>";
show_text(5,'status_box');
}
//
function set_sx(an_sk) {
skin_frame.style.background = "url(" + eval("frame_"+ an_sk +".src") + ")";
skin_back.style.background = "url(" + eval("back_"+ an_sk +".src") + ")";
document.images.play_it.src = eval("play_" + an_sk + ".src");
document.images.stop_it.src = eval("stop_" + an_sk + ".src");
document.images.next_it.src = eval("next_" + an_sk + ".src");
document.images.prev_it.src = eval("prev_" + an_sk + ".src");
sel_skin = an_sk;
linktext[1] = ap_title[act_track];
show_text(1,'status_box');
}
//
function skin_set(sk_an) {
skin_frame.style.background = "url(" + eval("frame_"+ sk_an +".src") + ")";
skin_back.style.background = "url(" + eval("back_"+ sk_an +".src") + ")";
document.images.play_it.src = eval("play_" + sk_an + ".src");
document.images.stop_it.src = eval("stop_" + sk_an + ".src");
document.images.next_it.src = eval("next_" + sk_an + ".src");
document.images.prev_it.src = eval("prev_" + sk_an + ".src");
}
//
function help_show() {
show_text(7,'status_box');
}
//
function help_next(hlp_no) {
show_text(hlp_no,'status_box');
}
//
// Online Help Start
//adapted from Link Description script- www.dynamicdrive.com
var linktext=new Array()
linktext[0]="Sorry Dear,<br>No more Songs !"
linktext[1]= "Play";
linktext[2]="Track and Title Saved"
linktext[3]="PSV Playlist Restored,<br>Verify and Use."
linktext[4]="Edit Track"
linktext[5]="skin"
linktext[6]="Back up, Restore"
linktext[7]="<img src='skins/skin.png' align='left'>Skin - Click this, Click a Skin Thumbnail and Save to Set. <div  class='h_nav' onclick='help_next(8);'>Next</div>";
linktext[8]="<img src='skins/edit.png' align='left'><img src='skins/sg4.png' align='right'>Edit - Set Song Number, Click this, Edit the URL and Title, Save. <div class='h_nav'><font onclick='help_next(7);'>Prev</font>--<font onclick='help_next(9);'>Next</font></div>";
linktext[9]="<img src='skins/save.png' align='left'>Save - Click this to Save a Track Edit or after a PSV Playlist Restore. <div class='h_nav'><font onclick='help_next(8);'>Prev</font>--<font onclick='help_next(10);'>Next</font></div>";
linktext[10]="<img src='skins/backup.png' align='left'>Backup - Click this to copy PSV Playlist to your Text Editor. Auto Clipboard.<div  class='h_nav'><font onclick='help_next(9);'>Prev</font>--<font onclick='help_next(11);'>Next</font></div>";
linktext[11]="<img src='skins/restore.png' align='left'>Restore - Paste PSV Playlist from your Editor, Press Save.<div  class='h_nav'><font onclick='help_next(10);'>Prev</font>--<font onclick='help_next(12);'>Next</font></div>";
linktext[12]="<div  style='position:relative;top:0px;left:0px;float:left;margin: 2px 2px 2px 2px;'><img src='skins/sg2.png'><img src='skins/sg4.png'></div>Click wheels to go upto the Number Set plus 1.<div  class='h_nav' ><font onclick='help_next(11);'>Prev</font>--<font onclick='help_next(13);'>Next</font></div>";
linktext[13]="<img style='background: #E6E6FA;' src='skins/s0/play.png' align='left'>Play a Track with this.<br><br><img style='background: #E6E6FA;' src='skins/s0/stop.png' align='left'>Stop Song with this.<div  class='h_nav'><font onclick='help_next(12);'>Prev</font>--<font onclick='help_next(14);'>Next</font></div>";
linktext[14]="<img style='background: #E6E6FA;' src='skins/s0/prev.png' align='left'>This plays Prev. Song.<br><br><img style='background: #E6E6FA;' src='skins/s0/next.png' align='left'>This Plays Next Song.<div class='h_nav'><font onclick='help_next(13);'>Prev</font>--<font onclick='help_next(15);'>Next</font></div>";
linktext[15]="This Gadget needs Cookies to be enabled in Browser.<br><a href='http://www.sangear.net/2008/02/audio-music-player-gadget.html' target='_blank'>Audio Music Player Page</a><div class='h_nav'><font onclick='help_next(14);'>Prev</font>--<font onclick='help_next(7);'>Home</font></div>";
linktext[16]="";
//
//
var ns6=document.getElementById&&!document.all
var ie=document.all

function show_text(thetext, whichdiv){
//
restore_live =0;
edit_live = 0;
//
if (ie) eval("document.all."+whichdiv).innerHTML=linktext[thetext]
else if (ns6) document.getElementById(whichdiv).innerHTML=linktext[thetext]
}

function resetit(whichdiv){
if (ie) eval("document.all."+whichdiv).innerHTML=' '
else if (ns6) document.getElementById(whichdiv).innerHTML=' '
}
//  Online Help End
//
//flash clipboard copy component
//
function copy(text2copy) {
  if (window.clipboardData) {window.clipboardData.setData("text",text2copy);}
    else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="clip_board.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}
//from http://webchicanery.com/2006/11/14/clipboard-copy-javascript/
//
//check cookies enabled
function load_mem() {
createCookie('xyztest8def', 'ran',1);
if (readCookie('xyztest8def') == 'ran'){
read_mem();
}
else {
linktext[16]="Enable Cookies in your Browser!";
show_text(16,'status_box');
}
}
//end check
//
function save_mem() {
cook_file[0] = sel_skin + cook_file[0];
createCookie('audioplay1delabspsv0',cook_file[0],999);
createCookie('audioplay1delabspsv1',cook_file[1],999);
createCookie('audioplay1delabspsv2',cook_file[2],999);
createCookie('audioplay1delabspsv3',cook_file[3],999);
createCookie('audioplay1delabspsv4',cook_file[4],999);
createCookie('audioplay1delabspsv5',cook_file[5],999);
createCookie('audioplay1delabspsv6',cook_file[6],999);
createCookie('audioplay1delabspsv7',cook_file[7],999);
createCookie('audioplay1delabspsv8',cook_file[8],999);
createCookie('audioplay1delabspsv9',cook_file[9],999);
}
//
function read_mem() {
if (readCookie('audioplay1delabspsv0')){
cook_file[0] = readCookie('audioplay1delabspsv0');
cook_file[1] = readCookie('audioplay1delabspsv1');
cook_file[2] = readCookie('audioplay1delabspsv2');
cook_file[3] = readCookie('audioplay1delabspsv3');
cook_file[4] = readCookie('audioplay1delabspsv4');
cook_file[5] = readCookie('audioplay1delabspsv5');
cook_file[6] = readCookie('audioplay1delabspsv6');
cook_file[7] = readCookie('audioplay1delabspsv7');
cook_file[8] = readCookie('audioplay1delabspsv8');
cook_file[9] = readCookie('audioplay1delabspsv9');
//
sel_skin = cook_file[0].charAt(0);
skin_set(sel_skin);
cook_file[0] = cook_file[0].substring(1);
load_tracks();
}
}
//
window.onload=start_player;
//
//end